home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / emacs-complete / fsf / emacs / lwlib / lwlib-utils.c < prev    next >
C/C++ Source or Header  |  1994-05-16  |  4KB  |  169 lines

  1. /* Defines some widget utility functions.
  2.    Copyright (C) 1992 Lucid, Inc.
  3.  
  4. This file is part of the Lucid Widget Library.
  5.  
  6. The Lucid Widget Library is free software; you can redistribute it and/or 
  7. modify it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. The Lucid Widget Library is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of 
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU Emacs; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include <X11/Xatom.h>
  21. #include <X11/IntrinsicP.h>
  22. #include <X11/ObjectP.h>
  23. #include "lwlib-utils.h"
  24.  
  25. /* Redisplay the contents of the widget, without first clearing it. */
  26. void
  27. XtNoClearRefreshWidget (widget)
  28.      Widget widget;
  29. {
  30.   XEvent event;
  31.  
  32.   event.type = Expose;
  33.   event.xexpose.serial = 0;
  34.   event.xexpose.send_event = 0;
  35.   event.xexpose.display = XtDisplay (widget);
  36.   event.xexpose.window = XtWindow (widget);
  37.   event.xexpose.x = 0;
  38.   event.xexpose.y = 0;
  39.   event.xexpose.width = widget->core.width;
  40.   event.xexpose.height = widget->core.height;
  41.   event.xexpose.count = 0;
  42.  
  43.   (*widget->core.widget_class->core_class.expose)
  44.     (widget, &event, (Region)NULL);
  45. }
  46.  
  47.  
  48. /* 
  49.  * Apply a function to all the subwidgets of a given widget recursively.
  50. */
  51. void
  52. XtApplyToWidgets (w, proc, arg)
  53.      Widget w;
  54.      XtApplyToWidgetsProc proc;
  55.      XtPointer arg;
  56. {
  57.   if (XtIsComposite (w))
  58.     {
  59.       CompositeWidget cw = (CompositeWidget) w;
  60.       /* We have to copy the children list before mapping over it, because
  61.      the procedure might add/delete elements, which would lose badly.
  62.      */
  63.       int nkids = cw->composite.num_children;
  64.       Widget *kids = (Widget *) malloc (sizeof (Widget) * nkids);
  65.       int i;
  66.       lwlib_bcopy (cw->composite.children, kids, sizeof (Widget) * nkids);
  67.       for (i = 0; i < nkids; i++)
  68. /* This prevent us from using gadgets, why is it here? */
  69. /*    if (XtIsWidget (kids [i])) */
  70.       {
  71.         /* do the kiddies first in case we're destroying */
  72.         XtApplyToWidgets (kids [i], proc, arg);
  73.         proc (kids [i], arg);
  74.       }
  75.       free (kids);
  76.     }
  77. }
  78.  
  79.  
  80. /*
  81.  * Apply a function to all the subwidgets of a given widget recursively.
  82.  * Stop as soon as the function returns non NULL and returns this as a value.
  83.  */
  84. void *
  85. XtApplyUntilToWidgets (w, proc, arg)
  86.      Widget w;
  87.      XtApplyUntilToWidgetsProc proc;
  88.      XtPointer arg;
  89. {
  90.   void* result;
  91.   if (XtIsComposite (w))
  92.     {
  93.       CompositeWidget cw = (CompositeWidget)w;
  94.       int i;
  95.       for (i = 0; i < cw->composite.num_children; i++)
  96.     if (XtIsWidget (cw->composite.children [i])){
  97.       result = proc (cw->composite.children [i], arg);
  98.       if (result)
  99.         return result;
  100.       result = XtApplyUntilToWidgets (cw->composite.children [i], proc,
  101.                       arg);
  102.       if (result)
  103.         return result;
  104.     }
  105.     }
  106.   return NULL;
  107. }
  108.  
  109.  
  110. /*
  111.  * Returns a copy of the list of all children of a composite widget
  112.  */
  113. Widget *
  114. XtCompositeChildren (widget, number)
  115.      Widget widget;
  116.      unsigned int* number;
  117. {
  118.   CompositeWidget cw = (CompositeWidget)widget;
  119.   Widget* result;
  120.   int n;
  121.   int i;
  122.  
  123.   if (!XtIsComposite (widget))
  124.     {
  125.       *number = 0;
  126.       return NULL;
  127.     }
  128.   n = cw->composite.num_children;
  129.   result = (Widget*)XtMalloc (n * sizeof (Widget));
  130.   *number = n;
  131.   for (i = 0; i < n; i++)
  132.     result [i] = cw->composite.children [i];
  133.   return result;
  134. }
  135.  
  136. Boolean
  137. XtWidgetBeingDestroyedP (widget)
  138.      Widget widget;
  139. {
  140.   return widget->core.being_destroyed;
  141. }
  142.  
  143. void
  144. XtSafelyDestroyWidget (widget)
  145.      Widget widget;
  146. {
  147. #if 0
  148.  
  149.   /* this requires IntrinsicI.h (actually, InitialI.h) */
  150.  
  151.   XtAppContext app = XtWidgetToApplicationContext(widget);
  152.  
  153.   if (app->dispatch_level == 0)
  154.     {
  155.       app->dispatch_level = 1;
  156.       XtDestroyWidget (widget);
  157.       /* generates an event so that the event loop will be called */
  158.       XChangeProperty (XtDisplay (widget), XtWindow (widget),
  159.                XA_STRING, XA_STRING, 32, PropModeAppend, NULL, 0);
  160.       app->dispatch_level = 0;
  161.     }
  162.   else
  163.     XtDestroyWidget (widget);
  164.   
  165. #else
  166.   abort ();
  167. #endif
  168. }
  169.